﻿<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE	html PUBLIC	"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html	xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"	/>
 <title>贵美商城</title>
 <link rel="stylesheet"	type="text/css"	href="css/global.css"	/>
 <link rel="stylesheet"	type="text/css"	href="css/layout.css"	/>
 	<script type="text/JavaScript">
	var strHome = 'http://www.gmgw.com';
	function addFav(){
		switch(getNav()){
			case 1:
			  window.external.addFavorite(strHome,'贵美商城');
			  break;
			case 2:
			  window.sidebar.addPanel('贵美商城',strHome,'');
			  break;
			case 0:
			  alert("加入收藏失败");
			  break;
		}		
		function getNav(){
			if(navigator.userAgent.indexOf("MSIE")!=-1)    return 1;
			if(navigator.userAgent.indexOf("Firefox")!=-1) return 2;
			return 0;
			}
	}
	function setHome(oThis){
		oThis.style.behavior='url(#default#homepage)';
		oThis.setHomePage(strHome);
		return false;
	} 	
	function showTime(){
		now=new Date;
		document.write(now.getFullYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日"+now.getHours()+"点"+now.getMinutes()+"分");
		
	}

	document.getElementById('logoutButton').addEventListener('click', function() {
		// 发送请求到服务器以退出登录
		fetch('/loginoutServlet', {
			method: 'GET', // 或者 'GET'，取决于后端API的要求
			// 如果有必要，可以在请求头中添加额外的信息，例如CSRF令牌
		})
				.then(response => response.json())
				.then(data => {
					if (data.success) {
						// 退出登录成功，可以重定向到登录页面或刷新页面
						window.location.href = '/login.jsp'; // 或者使用window.location.reload()
					} else {
						// 处理错误情况
						alert('退出登录失败');
					}
				})
				.catch(error => {
					// 处理请求错误
					alert('请求失败：' + error);
				});
	});


	</script>
</head>
<body>
		<div id="header">
			<div id="logo"></div>
			<div class="menu">
				<ul>
					<li class="pic pic1"></li>
					<li class="txt"><a href="buy.jsp" target="_parent">购物车</a></li>
					<li class="pic pic2"></li>
					<li class="txt"><a href="help.jsp" target="_parent">帮助中心</a></li>
					<li class="pic pic3"></li>
					<li class="txt"><a href="JavaScript:void(0);" onclick="addFav();">加入收藏</a></li>		
					<li class="pic pic4"></li>
					<li class="txt"><a href="JavaScript:void(0);" onclick="setHome(this);">设为首页</a></li>
					<c:choose>
						<c:when test="${not empty sessionScope.userList}">
							<ul>
								<c:forEach items="${sessionScope.userList}" var="user">
									<c:if test="${user.username!=null}">
										<li class="txt">${user.username}</li>
									</c:if>
									<c:if test="${user.username==null}">
										<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>
									</c:if>
								</c:forEach>
							</ul>
						</c:when>
						<c:otherwise>
							<li class="pic btn txt"><a href="login.jsp" target="_parent">登录</a></li>
						</c:otherwise>
					</c:choose>

<%--										<a href="http://localhost:8080/shopping/loginoutServlet">退出登录</a>--%>
<%--					<li class="pic btn txt"><a href="login.jsp" target="_parent">登录</a></li>--%>
					<li class="pic btn txt"><a href="register.jsp" target="_parent">注册</a></li>
				</ul>
			</div> <!--menu	end-->
			<div class="f_r w62p">
				<ul>
<%--					<c:forEach items="${sessionScope.userList}" var="user">--%>
<%--					<c:if test="${user.username!=null}">--%>
<%--						<li class="txt">你好,欢迎${user.username}访问贵美商城<script type="text/JavaScript">showTime();</script></li>--%>
<%--					</c:if>--%>
<%--						<c:if test="${user.username==null}">--%>
<%--							<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>--%>
<%--						</c:if>--%>
<%--					</c:forEach>--%>
<%--					<c:if test="${userList.username == null}">--%>
<%--						<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>--%>
<%--					</c:if>--%>

	<%@ page contentType="text/html;charset=UTF-8" language="java" %>
	<html>
	<head>
		<title>Welcome</title>
	</head>
	<body>
	<c:choose>
		<c:when test="${not empty sessionScope.userList}">
			<ul>
				<c:forEach items="${sessionScope.userList}" var="user">
					<c:if test="${user.username!=null}">
						<li class="txt">你好,欢迎${user.username}访问贵美商城<script type="text/JavaScript">showTime();</script></li>
					</c:if>
					<c:if test="${user.username==null}">
						<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>
					</c:if>
				</c:forEach>
			</ul>
		</c:when>
		<c:otherwise>
			<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>
		</c:otherwise>
	</c:choose>
	</body>
	</html>


<%--	<c:choose>--%>
<%--		<c:when test="${not empty sessionScope.userList}">--%>
<%--			<c:forEach items="${sessionScope.userList}" var="user">--%>
<%--				<c:if test="${user.username!=null}">--%>
<%--					<li class="txt">你好,欢迎${user.username}访问贵美商城<script type="text/JavaScript">showTime();</script></li>--%>
<%--				</c:if>--%>
<%--				<c:if test="${user.username==null}">--%>
<%--					<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>--%>
<%--				</c:if>--%>
<%--			</c:forEach>--%>
<%--		</c:when>--%>
<%--		<c:otherwise>--%>
<%--			<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>--%>
<%--		</c:otherwise>--%>
<%--	</c:choose>--%>



<%--					<%String username = request.getSession().getAttribute("username").toString();%>--%>
<%--	<%=username %>--%>
<%--					<li class="txt hello">你好，欢迎访问贵美商城！<script type="text/JavaScript">showTime();</script></li>--%>
				</ul>
			</div> 
  		<div class="nav f_l w100p">
  			<ul>
  				<li><a href="index.jsp" target="_parent">&nbsp;首&nbsp;&nbsp;&nbsp;页&nbsp;</a></li>
  				<li><a href="catlist.jsp" target="_parent">家用电器</a></li>
  				<li><a href="catlist3.jsp" target="_parent">手机数码</a></li>
  				<li><a href="catlist4.jsp" target="_parent">日用百货</a></li>
  				<li><a href="catlist2.jsp" target="_parent">&nbsp;书&nbsp;&nbsp;&nbsp;籍&nbsp;</a></li>
  				<li><a href="help.jsp" target="_parent">帮助中心</a></li>
  				<li><a href="help.jsp" target="_parent">免费开店</a></li>
  				<li><a href="help.jsp" target="_parent">全球咨询</a></li>
  			</ul>
  		</div>	<!--nav	end-->		
		</div> <!--header	end-->	
 </body>
</html>
